function OS_Skill(host,id)
{
	this.$super=OS_Resource;
	if (this.$super(host,id)===false) return;
	delete this.$super;
	
	this.actions=[];
	
	this.load=function(handler)
	{
		var children=this.resourceNode.childNodes;
		for (var i=0;i<children.length;i++)
		{
			if (children[i].nodeType!=1) continue;
			var child=children[i];
			switch(child.nodeName)
			{
				case "name":
					var childValue=child.childNodes[0].nodeValue;
					this.name=childValue;
					break;
				case "selectTarget":
					var childValue=child.childNodes[0].nodeValue;
					this.selectTarget=childValue;
					break;
				case "selectCount":
					var childValue=child.childNodes[0].nodeValue;
					this.selectCount=childValue;
					break;
				case "cost":
					var childValue=child.childNodes[0].nodeValue;
					this.cost=childValue;
					break;
				case "actions":
					var actionList=child.childNodes;
					for (var j=0;j<actionList.length;j++)
					{
						if (actionList[j].nodeType!=1) continue;
						var actionNode=actionList[j];
						var action={name:actionNode.nodeName};
						for (k=0;k<actionNode.attributes.length;k++)
						{
							action[actionNode.attributes[k].nodeName]=actionNode.attributes[k].nodeValue;
						}
						this.actions.push(action);
					}
					break;
			}
		}
		this.loaded=true;
		handler(this);
	}
	
	this.update=function(battle,source,target,starttime)
	{
		var nowTime=(new Date()).getTime();
		var timeTemp=nowTime-starttime;
		for (var i=0;i<this.actions.length;i++)
		{
			var action=this.actions[i];
			switch(action.name)
			{
				case "walkForwardAction":
					var duration=1500;
					var fromPosition={x:source.position.x,y:source.position.y};
					var toPosition={x:target[0].position.x,y:target[0].position.y};
					if (target[0].faceto=="down")
					{
						toPosition.x-=32;
						toPosition.y+=26;
					}
					else
					{
						toPosition.x+=32;
						toPosition.y-=26;
					}
					if (timeTemp<duration)
					{
						source.currentPosition.x=fromPosition.x+(toPosition.x-fromPosition.x)*timeTemp/duration;
						source.currentPosition.y=fromPosition.y+(toPosition.y-fromPosition.y)*timeTemp/duration;
						var index=Math.floor(timeTemp/duration*12)%4+1;
						var suffix="";
						if (toPosition.y<fromPosition.y) suffix="b";
						else suffix="f";
						source.currentFrame=source.actor.actions["walk"+suffix+index];
						return false;
					}
					else
					{
						source.currentPosition.x=toPosition.x;
						source.currentPosition.y=toPosition.y;
						timeTemp-=duration;
					}
					break;
				case "walkBackAction":
					var duration=1500;
					var fromPosition={x:target[0].position.x,y:target[0].position.y};
					var toPosition={x:source.position.x,y:source.position.y};
					if (target[0].faceto=="down")
					{
						fromPosition.x-=32;
						fromPosition.y+=26;
					}
					else
					{
						fromPosition.x+=32;
						fromPosition.y-=26;
					}
					if (timeTemp<duration)
					{
						source.currentPosition.x=fromPosition.x+(toPosition.x-fromPosition.x)*timeTemp/duration;
						source.currentPosition.y=fromPosition.y+(toPosition.y-fromPosition.y)*timeTemp/duration;
						var index=Math.floor(timeTemp/duration*12)%4+1;
						var suffix="";
						if (toPosition.y<fromPosition.y) suffix="b";
						else suffix="f";
						source.currentFrame=source.actor.actions["walk"+suffix+index];
						return false;
					}
					else
					{
						source.currentPosition.x=toPosition.x;
						source.currentPosition.y=toPosition.y;
						var suffix="";
						if (source.faceto=="up") suffix="b";
						else suffix="f";
						source.currentFrame=source.actor.actions["stand"+suffix];
						timeTemp-=duration;
					}
					break;
				case "teleportForwardAction":
					var duration=500;
					var fromPosition={x:source.position.x,y:source.position.y};
					var toPosition={x:target[0].position.x,y:target[0].position.y};
					if (target[0].faceto=="down")
					{
						toPosition.x-=32;
						toPosition.y+=26;
					}
					else
					{
						toPosition.x+=32;
						toPosition.y-=26;
					}
					if (timeTemp<duration)
					{
						if (timeTemp<duration/2)
						{
							source.currentPosition.x=fromPosition.x;
							source.currentPosition.y=fromPosition.y;
						}
						else
						{
							source.currentPosition.x=toPosition.x;
							source.currentPosition.y=toPosition.y;
						}
						return false;
					}
					else
					{
						source.currentPosition.x=toPosition.x;
						source.currentPosition.y=toPosition.y;
						timeTemp-=duration;
					}
					break;
				case "teleportBackAction":
					var duration=1500;
					var fromPosition={x:target[0].position.x,y:target[0].position.y};
					var toPosition={x:source.position.x,y:source.position.y};
					if (target[0].faceto=="down")
					{
						fromPosition.x-=32;
						fromPosition.y+=26;
					}
					else
					{
						fromPosition.x+=32;
						fromPosition.y-=26;
					}
					if (timeTemp<duration)
					{
						if (timeTemp<duration/2)
						{
							source.currentPosition.x=fromPosition.x;
							source.currentPosition.y=fromPosition.y;
						}
						else
						{
							source.currentPosition.x=toPosition.x;
							source.currentPosition.y=toPosition.y;
						}
						return false;
					}
					else
					{
						source.currentPosition.x=toPosition.x;
						source.currentPosition.y=toPosition.y;
						var suffix="";
						if (source.faceto=="up") suffix="b";
						else suffix="f";
						source.currentFrame=source.actor.actions["stand"+suffix];
						timeTemp-=duration;
					}
					break;
				case "attackAction":
					var duraion=1500;
					if (timeTemp<duration)
					{
						var index=Math.floor(timeTemp/duration*6);
						var suffix="";
						if (target[0].faceto=="down") suffix="b";
						else suffix="f";
						if (index==0 || index==5)
						{
							source.currentFrame=source.actor.actions["stand"+suffix];
						}
						else
						{
							source.currentFrame=source.actor.actions["attack"+suffix+index];
						}
						if (target[0].faceto=="down") suffix="f";
						else suffix="b";
						if (index==3 || index==2)
						{
							target[0].currentFrame=target[0].actor.actions["hurt"+suffix];
						}
						return false;
					}
					else
					{
						var suffix="";
						if (target[0].faceto=="down") suffix="f";
						else suffix="b";
						target[0].currentFrame=target[0].actor.actions["stand"+suffix];
						timeTemp-=duration;
					}
					break;
				case "healing":
					for (var k=0;k<target.length;k++)
					{
						if (!target[k].hurtInfo)
						{
							var healthP=Number(action.healthPoint);
							healthP+=source.magic;
							healthP+=Math.floor(source.magic*Math.random());
							target[k].hp+=healthP;
							if (target[k].hp>target[k].maxHp)
							{
								healthP-=target[k].hp-target[k].maxHp;
								target[k].hp=target[k].maxHp;
							}
							target[k].hurtInfo={damage:healthP,startTime:(new Date()).getTime(),type:"heal"};
						}
					}
					break;
				case "makeHurt":
					for (var k=0;k<target.length;k++)
					{
						if (!target[k].hurtInfo)
						{
							damage=Number(action.baseDamage);
							if (action.type=="physical")
							{
								damage+=source.attack;
								damage+=Math.floor(source.attack*Math.random());
								damage-=target[k].defense;
								for(var m=0;m<target[k].states.length;m++)
								{
									if(target[k].states[m].test("defense"))
									{
										damage-=20;
										break;
									}
								}
							}
							else if (action.type=="magic")
							{
								damage+=source.magic;
								damage+=Math.floor(source.magic*Math.random());
								damage-=target[k].resistance;
								for(var m=0;m<target[k].states.length;m++)
								{
									if(target[k].states[m].test("defense"))
									{
										damage-=20;
										break;
									}
								}
							}
							if (damage<0) damage=0;
							target[k].hp-=damage;
							if (target[k].hp<0) target[k].hp=0;
							if (target[k].hp==0)
							{
								target[k].alive=false;
								target[k].activePoint=0;
							}
							target[k].hurtInfo={damage:-damage,startTime:(new Date()).getTime(),type:"hurt"};
						}
					}
					break;
				case "makeState":
					for(var k=0;k<target.length;k++)
					{
						if (!target[k].hurtInfo)
						{
							var state=new OS_BattlerState();
							state.setName(action.state);
							state.setNum(action.delay);
							target[k].states.push(state);
							
							var statesLabel={"chaos":"狂乱","sleep":"睡眠","block":"封印","defense":"防御"};
							target[k].hurtInfo={damage:statesLabel[action.state],startTime:(new Date()).getTime(),type:"state"};
						}
					}
				    break;
				case "playBattleEffect":
					var effect=OS_Resource.resource.get(action.effect);
					var duration=action.duration;
					if (timeTemp<duration)
					{
						var position_temp=null;
						var index=Math.floor(effect.length*timeTemp/duration);
						if (action.position=="source")
						{
							position_temp=source;
							var left=position_temp.currentPosition.x-effect.offset.x;
							var top=position_temp.currentPosition.y-effect.offset.y;
							battle.putEffect(effect.timeLine[index],left,top);
						}
						else
						{
							for (var k=0;k<target.length;k++)
							{
								position_temp=target[k];
								var left=position_temp.currentPosition.x-effect.offset.x;
								var top=position_temp.currentPosition.y-effect.offset.y;
								battle.putEffect(effect.timeLine[index],left,top);
								if (action.hurt=="true")
								{
									if (target[k].faceto=="down") suffix="f";
									else suffix="b";
									target[k].currentFrame=target[k].actor.actions["hurt"+suffix];
								}
							}
						}
						return false;
					}
					else
					{
						for (var k=0;k<target.length;k++)
						{
							if (target[k].faceto=="down") suffix="f";
							else suffix="b";
							if (action.hurt=="true")
							{
								target[k].currentFrame=target[k].actor.actions["stand"+suffix];
							}
						}
						timeTemp-=duration;
					}
					break;
				case "delay":
					var duration=action.time;
					if (timeTemp<duration)
					{
						return false;
					}
					else
					{
						timeTemp-=duration;
					}
			}
		}
		for (var i=0;i<target.length;i++)
		{
			delete target[i].hurtInfo;
		}
		//进行结算
		return true;
	}
}

OS_Resource.Builder.put("skill",OS_Skill);